package messages;

import java.io.IOException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import connection.exception.ConnectionResetException;

import utils.Serialization;
import utils.XmlSerializationUtils;

public class NonceToSignResponseMessage implements Convertible {

    private static final long serialVersionUID = 1L;

    public Integer _nonce;
    
    public NonceToSignResponseMessage(){}
    
    public NonceToSignResponseMessage(Integer nonce) {
        _nonce = nonce;
    }
    
    @Override
    public Element convertToCanonic(Document doc) {

        String className = getClass().getSimpleName();
        
        Element el = doc.createElement(className);
        
        Element childEl = doc.createElement("nonce");
        childEl.setTextContent(_nonce.toString());
        el.appendChild(childEl);

        return el;
    } 


    @Override
    public Object convertFromCanonic(Element el) {
        this._nonce = XmlSerializationUtils.getIntValue(el, "nonce");
        return this;
    }
    
    public static void main(String[] args) throws ConnectionResetException, IOException{

        NonceToSignResponseMessage gen = new NonceToSignResponseMessage(1000);

        byte[] serialized = Serialization.Serialize(gen);

        Object newGen = Serialization.Deserialize(serialized);

        newGen.toString();

        System.in.read();
    }
}
